from flask import current_app
from flask_restx import abort

from app.api.v1.collector.urls import collectorBlueprint
from configs.settings import flask_config
from monitor.redis_pool import OPRedis

node_list = flask_config.node_list


@collectorBlueprint.route("/", methods=["GET"])
def get_data():
    try:
        conn = OPRedis()
        res = {}
        for key in node_list:
            res[key] = conn.get_list_value(key, 0, -1)
        return {"code": 200, "data": res}

    except Exception as e:
        current_app.logger.exception(e)
        abort(500, message="参数错误")
